using System;
using System.ServiceModel;
using System.ServiceModel.Channels;

using Pegasus.Log4Net;

namespace Pegasus.ServiceModel
{
	/// <summary>
	/// This class is used to filter any incomming broadcast message that this node sent.
	/// </summary>
	internal class NodeFilterMessagesFromSelf : PeerMessagePropagationFilter
	{
		// Local Instance Values
		private ILog m_log = LogManager.GetLogger( typeof( NodeFilterMessagesFromSelf ) );

		/// <summary>
		/// Initializes a new instance of the <see cref="NodeFilterMessagesFromSelf"/> class.
		/// </summary>
		public NodeFilterMessagesFromSelf()
		{
		}

		/// <summary>
		/// Shoulds the message propagate.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <param name="origination">The origination.</param>
		/// <returns></returns>
		public override PeerMessagePropagation ShouldMessagePropagate( Message message, PeerMessageOrigination origination )
		{
			PeerMessagePropagation destination = PeerMessagePropagation.LocalAndRemote;

			if( origination == PeerMessageOrigination.Local )
			{
				destination = PeerMessagePropagation.Remote;
			}

			return destination;
		}
	}
}
